package fundamental;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;

import static fundamental.Params.*;

public class GiantTSP {
    public ArrayList<Point> tour;
    public ArrayList<Point> tourBase;
    public ArrayList<Point> validTour;  //  剔除same节点的tour
    public ArrayList<Point> path;
    public HashSet<Cand> openedCandBase;
    public int cap1;
    public int cap2;

    public GiantTSP(int cap1, int cap2) {
        tour = new ArrayList<>();
        tourBase = new ArrayList<>();
        path = new ArrayList<>();
        openedCandBase = new HashSet<>(openedCandSet);
        this.cap1 = cap1;
        this.cap2 = cap2;
        for (FirstVehicle v1: firstVehicleList
             ) {
            for (Point cand: v1.route.subList(1, v1.route.size()-1)) {
                if (cand instanceof Cand) {
                    for (SecondVehicle v2: secondVehicleList
                         ) {
                        if (v2.start_end == cand) {
                            tour.addAll(v2.route.subList(1, v2.route.size()-1));
                        }
                    }
                }
            }
        }
        getTourBase();
    }

    /**
     * 移除tour中与openCand的same相同的客户，并更新二级路径
     */
    public void getValidTour() {
        validTour = new ArrayList<>(tour);
        validTour.removeIf(o ->openedCandSet.contains(((Customer)o).sameCand));
        for (Cand cand: openedCandSet
             ) {
            SecondVehicle v = new SecondVehicle(cap2, vFix2, vvar2);
            v.add(cand);
            v.add(cand.sameCust);
            v.add(cand);
            v.start_end = cand;
            cand.loading += cand.sameCust.demand+cand.sameCust.overDemand;
            secondVehicleList.add(v);
        }
    }

    public void getTourBase() {
        tourBase.clear();
        tourBase.addAll(tour);
    }

    public void resetTour() {
        tour.clear();
        tour.addAll(tourBase);
    }


}
